#include <stdio.h>
#include <stdlib.h>

#define MaxSize 50

typedef struct SqQueue
{
    int data[MaxSize];
    int front, rear;
} SqQueue;

void Print(SqQueue Q)
{
    printf("front->");
    for (int i = Q.front; i != Q.rear; i = (i + 1) % MaxSize)
        printf("%d->", Q.data[i]);
    printf("rear\n");
}

void InitQueue(SqQueue &Q)
{
    Q.front = Q.rear = 0;
    printf("初始化: \n");
    Print(Q);
}

bool IsEmpty(SqQueue Q)
{
    if (Q.front == Q.rear)
        return true;
    return false;
}

bool IsFull(SqQueue Q)
{
    if ((Q.rear + 1) % MaxSize == Q.front)
        return true;
    return false;
}

bool EnQueue(SqQueue &Q, int e)
{
    if (IsFull(Q))
        return false;
    Q.data[Q.rear] = e;
    Q.rear = (Q.rear + 1) % MaxSize;
    printf("%d 入队: \n", e);
    Print(Q);
    return true;
}

bool DeQueue(SqQueue &Q, int &e)
{
    if (IsEmpty(Q))
        return false;
    e = Q.data[Q.front];
    Q.front = (Q.front + 1) % MaxSize;
    printf("%d 出队: \n", e);
    Print(Q);
    return true;
}

int main()
{
    SqQueue Q;
    int e;
    InitQueue(Q);
    EnQueue(Q, 3);
    EnQueue(Q, 4);
    EnQueue(Q, 5);
    DeQueue(Q, e);
    DeQueue(Q, e);
    DeQueue(Q, e);
    return 0;
}